package Map;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * @author 王艺锡
 * @version 1.0
 */
@SuppressWarnings({"all"})
public class Exercise {
    public static void main(String[] args) {
        HashMap hashMap = new HashMap();

        hashMap.put(1,new Employer("jack", "0001", 13500));
        hashMap.put(2,new Employer("lihua", "0002", 1500));
        hashMap.put(3,new Employer("wyx", "0003", 23000));

        System.out.println("=====第1种=====");
        Set keyset = hashMap.keySet();
        for (Object key :keyset) {
            Employer e = (Employer)hashMap.get(key);
            if(e.getSal() > 18000){
                System.out.println(key + "_" + hashMap.get(key));
            }
        }

        System.out.println("=====第2种=====");
        Iterator iterator = keyset.iterator();
        while (iterator.hasNext()) {
            Object key = iterator.next();
            Employer e = (Employer)hashMap.get(key);
            if(e.getSal() > 18000){
                System.out.println(key + "_" + hashMap.get(key));
            }
        }

        System.out.println("=====第3种=====");
        Set entrySet = hashMap.entrySet();
        for (Object entry :entrySet) {
            Map.Entry m =  (Map.Entry)entry;
            Employer e = (Employer)m.getValue();
            if(e.getSal() > 18000){
                System.out.println(m.getKey() + "_" + m.getValue());
            }
        }

        System.out.println("=====第4种=====");
        Iterator iterator1 = entrySet.iterator();
        while (iterator1.hasNext()) {
            Object node = iterator1.next();
            Map.Entry m = (Map.Entry)node;
            Employer e =  (Employer)m.getValue();
            if(e.getSal() > 18000){
                System.out.println(m.getKey() + "_" + m.getValue());
            }
        }



    }
}

class Employer{
    private String name;
    private String id;
    private double sal;

    public Employer(String name, String id, double sal) {
        this.name = name;
        this.id = id;
        this.sal = sal;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public double getSal() {
        return sal;
    }

    public void setSal(double sal) {
        this.sal = sal;
    }

    @Override
    public String toString() {
        return name + "_" + id + "_" + sal;
    }
}
